﻿using System;

namespace AT.IBMS.Framework.Controls
{

    public partial class AspNetPager
    {

        /// <summary>
        /// PostBack方式分页时，当页导航元素之一被单击或用户手工输入页索引提交时发生，Url方式分页时，页面第一次加载时发生。
        /// </summary>
        /// <remarks>
        ///       该事件在 AspNetPager 处理分页操作前引发，因此可以在事件处理程序中根据需要取消分页操作。
        ///     </remarks>
        ///     <example>
        ///       下面的示例显示如何为PageChanging事件指定事件处理程序，当用户选中页面上的“取消分页”复选框时，取消分页操作：
        ///       <code>
        ///         <![CDATA[
        /// <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
        /// <%@Import NameSpace="System.Data" %>
        /// <%@Import Namespace="System.Data.SqlClient" %>
        /// <script runat="server" Language="C#">
        /// void Page_Load(object sender, EventArgs e)
        ///     {
        ///         if (!IsPostBack)
        ///         {
        ///             int totalOrders = (int)SqlHelper.ExecuteScalar(CommandType.StoredProcedure, "P_GetOrderNumber");
        ///             AspNetPager1.RecordCount = totalOrders;
        ///             bindData();
        ///         }
        ///     }
        /// 
        ///  void bindData()
        ///     {
        ///         Repeater1.DataSource = SqlHelper.ExecuteReader(CommandType.StoredProcedure,"P_GetPagedOrders2005",
        ///             new SqlParameter("@startIndex", AspNetPager1.StartRecordIndex),
        ///             new SqlParameter("@pageSize", AspNetPager1.PageSize));
        ///         Repeater1.DataBind();
        ///     }
        /// 
        /// void AspNetPager1_PageChanging(object src,PageChangingEventArgs e){
        ///  Response.Write("PageChanging事件被引发，新页面的索引是：" + e.NewPageIndex);
        /// if(CheckBox1.Checked){
        ///     e.Cancel=true;
        ///     Response.Write("<br/>分页操作被取消");
        ///  }
        /// }
        /// 
        ///  void AspNetPager1_PageChanged(object src, EventArgs e)
        ///     {
        ///         bindData();
        ///         Response.Write("<br/>PageChanged事件被引发，当前页索引是："+AspNetPager1.CurrentPageIndex);
        ///     }
        /// </script>
        /// <HTML><HEAD>
        /// <TITLE> AspNetPager Samples </TITLE>
        /// <META NAME="Author" CONTENT="Webdiyer (www.webdiyer.com)">
        /// </HEAD>
        /// 
        /// <BODY>
        /// <form runat="server">
        ///     <webdiyer:aspnetpager id="AspNetPager1" runat="server" OnPageChanging="AspNetPager1_PageChanging" onpagechanged="AspNetPager1_PageChanged" 
        ///     Width="100%" HorizontalAlign="center"></webdiyer:aspnetpager>
        ///     <asp:CheckBox ID="CheckBox1" runat="server" Text="取消分页" />
        ///         <asp:Repeater ID="Repeater1" runat="server">
        ///         <HeaderTemplate>
        ///         <table width="100%" border="1" cellspacing="0" cellpadding="4" style="border-collapse:collapse">
        ///         <tr style="backGround-color:#CCCCFF"><th style="width:15%"><asp:Literal ID="Literal1" runat="server" Text="<%$Resources:LocalizedText,orderid%>" /></th><th style="width:15%"><asp:Literal ID="Literal3" runat="server" Text="<%$Resources:LocalizedText,orderdate%>" /></th><th style="width:30%"><asp:Literal ID="Literal5" runat="server" Text="<%$Resources:LocalizedText,companyname%>" /></th><th style="width:20%"><asp:Literal ID="Literal2" runat="server" Text="<%$Resources:LocalizedText,customerid%>" /></th><th style="width:20%"><asp:Literal ID="Literal4" runat="server" Text="<%$Resources:LocalizedText,employeename%>" /></th></tr>
        ///         </HeaderTemplate>
        ///         <ItemTemplate>
        ///         <tr style="background-color:#FAF3DC">
        ///         <td><%#DataBinder.Eval(Container.DataItem,"orderid")%></td>
        ///         <td><%#DataBinder.Eval(Container.DataItem,"orderdate","{0:d}")%></td>
        ///         <td><%#DataBinder.Eval(Container.DataItem, "companyname")%></td>
        ///         <td><%#DataBinder.Eval(Container.DataItem,"customerid")%></td>
        ///         <td><%#DataBinder.Eval(Container.DataItem,"employeename")%></td>
        ///         </tr>
        ///         </ItemTemplate>
        ///         <FooterTemplate>
        ///         </table>
        ///         </FooterTemplate>
        ///         </asp:Repeater>
        ///         <webdiyer:AspNetPager ID="AspNetPager2" runat="server" CloneFrom="AspNetPager1">
        ///         </webdiyer:AspNetPager>
        ///         </form>
        /// </BODY>
        /// </HTML>
        /// 
        ///         ]]>
        ///       </code>
        ///     </example>
        public event PageChangingEventHandler PageChanging
        {
            add
            {
                Events.AddHandler(EventPageChanging, value);
            }
            remove
            {
                Events.RemoveHandler(EventPageChanging, value);
            }
        }

        /// <summary>
        /// PostBack方式分页时，当页导航元素之一被单击或用户手工输入页索引提交时发生，Url方式分页时，页面第一次加载时发生。
        /// </summary>
        /// <remarks>
        ///       该事件被引发时，AspNetPager 已完成分页操作。
        ///     </remarks>
        ///     <example>
        ///       下面的示例显示如何为PageChanged事件指定和编写事件处理程序，在该事件处理程序中重新绑定Repeater上显示的数据：
        ///       <code>
        ///         <![CDATA[
        /// <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
        /// <%@Import NameSpace="System.Data"%>
        /// <%@Import NameSpace="System.Data.SqlClient"%>
        /// <script runat="server" Language="C#">
        /// void Page_Load(object sender, EventArgs e)
        ///     {
        ///         if (!IsPostBack)
        ///         {
        ///             int totalOrders = (int)SqlHelper.ExecuteScalar(CommandType.StoredProcedure, "P_GetOrderNumber");
        ///             AspNetPager1.RecordCount = totalOrders;
        ///             bindData();
        ///         }
        ///     }
        /// 
        ///  void bindData()
        ///     {
        ///         Repeater1.DataSource = SqlHelper.ExecuteReader(CommandType.StoredProcedure,"P_GetPagedOrders2005",
        ///             new SqlParameter("@startIndex", AspNetPager1.StartRecordIndex),
        ///             new SqlParameter("@pageSize", AspNetPager1.PageSize));
        ///         Repeater1.DataBind();
        ///     }
        /// 
        ///  void AspNetPager1_PageChanged(object src, EventArgs e)
        ///     {
        ///         bindData();
        ///     }
        /// </script>
        /// <HTML><HEAD>
        /// <TITLE> AspNetPager Samples </TITLE>
        /// <META NAME="Author" CONTENT="Webdiyer (www.webdiyer.com)">
        /// </HEAD>
        /// 
        /// <BODY>
        /// <form runat="server">
        ///   <webdiyer:AspNetPager ID="AspNetPager1" runat="server" Width="100%" HorizontalAlign="right" PageSize="8" OnPageChanged="AspNetPager1_PageChanged">
        ///         </webdiyer:AspNetPager>
        ///         <asp:Repeater ID="Repeater1" runat="server">
        ///         <HeaderTemplate>
        ///         <table width="100%" border="1" cellspacing="0" cellpadding="4" style="border-collapse:collapse">
        ///         <tr style="backGround-color:#CCCCFF"><th style="width:15%"><asp:Literal ID="Literal1" runat="server" Text="<%$Resources:LocalizedText,orderid%>" /></th><th style="width:15%"><asp:Literal ID="Literal3" runat="server" Text="<%$Resources:LocalizedText,orderdate%>" /></th><th style="width:30%"><asp:Literal ID="Literal5" runat="server" Text="<%$Resources:LocalizedText,companyname%>" /></th><th style="width:20%"><asp:Literal ID="Literal2" runat="server" Text="<%$Resources:LocalizedText,customerid%>" /></th><th style="width:20%"><asp:Literal ID="Literal4" runat="server" Text="<%$Resources:LocalizedText,employeename%>" /></th></tr>
        ///         </HeaderTemplate>
        ///         <ItemTemplate>
        ///         <tr style="background-color:#FAF3DC">
        ///         <td><%#DataBinder.Eval(Container.DataItem,"orderid")%></td>
        ///         <td><%#DataBinder.Eval(Container.DataItem,"orderdate","{0:d}")%></td>
        ///         <td><%#DataBinder.Eval(Container.DataItem, "companyname")%></td>
        ///         <td><%#DataBinder.Eval(Container.DataItem,"customerid")%></td>
        ///         <td><%#DataBinder.Eval(Container.DataItem,"employeename")%></td>
        ///         </tr>
        ///         </ItemTemplate>
        ///         <FooterTemplate>
        ///         </table>
        ///         </FooterTemplate>
        ///         </asp:Repeater>
        ///         <webdiyer:AspNetPager ID="AspNetPager2" runat="server" CloneFrom="AspNetPager1">
        ///         </webdiyer:AspNetPager>
        ///         </form>
        /// </BODY>
        /// </HTML>
        ///  ]]>
        ///       </code><p>该示例所用的Sql Server存储过程代码如下（仅适用于SQL Server 2005）：</p><code>
        ///         <![CDATA[
        /// CREATE PROCEDURE P_GetPagedOrders2005
        ///     @startIndex INT, 
        ///     @pageSize INT 
        /// AS
        /// begin
        /// WITH orderList AS ( 
        /// SELECT ROW_NUMBER() OVER (ORDER BY O.orderid DESC)AS Row, O.orderid,O.orderdate,O.customerid,C.CompanyName,E.FirstName+' '+E.LastName as EmployeeName 
        /// from orders O
        /// left outer join Customers C
        /// on O.CustomerID=C.CustomerID
        /// left outer join Employees E
        /// on O.EmployeeID=E.EmployeeID)
        /// 
        /// SELECT orderid,orderdate,customerid,companyName,employeeName
        /// FROM orderlist
        /// WHERE Row between @startIndex and @startIndex+@pageSize-1
        /// end
        ///  ]]>
        ///       </code>
        ///     </example>
        public event EventHandler PageChanged
        {
            add
            {
                Events.AddHandler(EventPageChanged, value);
            }
            remove
            {
                Events.RemoveHandler(EventPageChanged, value);
            }
        }

    }

}
